#include "PathIntegrator.h"

using namespace OBR;

PathIntegrator::PathIntegrator() : Integrator("shaders/Integrator/PathIntegrator.cu")
{
    this->num_fbos = 1;
    this->program_desc.callables.entryFunctionNameCC = "__continuation_callable__path_integrator";
    this->program_desc.kind = OPTIX_PROGRAM_GROUP_KIND_CALLABLES;
    this->program_desc.flags = OPTIX_PROGRAM_GROUP_FLAGS_NONE;
}

PathIntegrator::~PathIntegrator()
{
}

void PathIntegrator::_buildFromConfig(const Json::Value &config)
{
    if (config.isMember("max depth"))
        this->settings.max_depth = config["max depth"].asUInt();
    if (config.isMember("num fbos"))
        this->settings.max_depth = config["num fbos"].asUInt();
    if (config.isMember("rr start"))
        this->settings.max_depth = config["rr start"].asUInt();
    if (config.isMember("rr max"))
        this->settings.max_depth = config["rr max"].asUInt();
    if (config.isMember("rr thres"))
        this->settings.max_depth = config["rr thres"].asUInt();
}

OptixProgramGroupOptions &PathIntegrator::getProgramGroupOptions()
{
    return this->program_opt;
}

OptixProgramGroupDesc &PathIntegrator::getProgramGroupDesc()
{
    this->program_desc.callables.moduleCC = this->cuda_module->optix_module;
    return this->program_desc;
}

void PathIntegrator::uploadSbtData()
{
    this->sbt_data.resize(sizeof(PathIntegratorData));
    this->sbt_data.upload(&(this->settings), sizeof(PathIntegratorData));
}